< previous page page_504 next page >

Page 504
e10a6a0a59f035e870d90cca05b85fce.gif
' Return the (X, Y, Z) coordinates of the
' Bezier surface for these u and v values.
Private Sub SurfaceValue( _
    ByVal u As Single, ByVal v As Single, _
    ByRef X As Single, ByRef Y As Single, ByRef Z As Single)
Dim P As Integer
Dim i As Integer
Dim j As Integer
Dim pt As Point3D
Dim Bix As Single
Dim Bjz As Single

    For i = 0 To MaxU
        ' Compute Bix.
        Bix = Factorial(MaxU) / Factorial(i) / _
            Factorial(MaxU - i) * _
            u ^ i * (1 - u) ^ (MaxU - i)

        For j = 0 To MaxV 
            ' Compute Bjz.
            Bjz = Factorial(MaxV) / Factorial(j) / _
                Factorial(MaxV - j) * _
                v ^ j * (1 - v) ^ (MaxV - j)

            ' Add to the coordinates.
            For P = 1 To 3
                pt.coord(P) = pt.coord(P) + _
                    Points(i, j).coord(P) * _
                    Bix * Bjz
            Next P
         Next j
    Next i

    ' Prepare the output.
    X = pt.coord(1)
    Y = pt.coord(2)
    Z = pt.coord(3)
End Sub

' Return the factorial of a number (n!).
Function Factorial(ByVal n As Single) As Single
Dim i As Integer
Dim tot As Single

    tot = 1
    For i = 2 To n
         tot = tot * i
    Next i
    Factorial = tot
End Function

 
< previous page page_504 next page >